package com.bootdo.hotel.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ModelAttribute;
import com.bootdo.common.controller.BaseController;
import com.bootdo.hotel.domain.HotelEveryDayMoney;
import com.bootdo.hotel.service.HotelEveryDayMoneyService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 房价码对应的每日价格
 * 
 * @author haojiangbo
 * @email 2100272728@qq.com
 * @date 2019-10-18 17:16:57
 */
 
@Controller
@RequestMapping("/hotel/hotelEveryDayMoney")
public class HotelEveryDayMoneyController extends BaseController{


	@Autowired
	private HotelEveryDayMoneyService hotelEveryDayMoneyService;
	
	@ModelAttribute
	public HotelEveryDayMoney get(@RequestParam(required=false) Long id) {
		if (id != null){
			return hotelEveryDayMoneyService.get(id);
		}else{
			return new HotelEveryDayMoney();
		}
	}


	
	//insert into sys_menu(parent_id,name,url,perms,type)  values (149,'测试','/hotel/hotelEveryDayMoney','hotel:hotelEveryDayMoney:hotelEveryDayMoney',1)
	//insert into sys_menu(parent_id,name,url,perms,type)  values (160,'修改','','hotel:hotelEveryDayMoney:edit',2)
	//type 0是分类菜单 1是小菜但 2是按钮
	@GetMapping()
	@RequiresPermissions("hotel:hotelEveryDayMoney:hotelEveryDayMoney")	
	String HotelEveryDayMoney(HotelEveryDayMoney hotelEveryDayMoney,HttpServletRequest request,HttpServletResponse response){
	    return "hotel/hotelEveryDayMoney/hotelEveryDayMoney";
	}
	
	@ResponseBody
	@PostMapping("/list")
	@RequiresPermissions("hotel:hotelEveryDayMoney:hotelEveryDayMoney")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<HotelEveryDayMoney> hotelEveryDayMoneyList = hotelEveryDayMoneyService.list(query);
		int total = hotelEveryDayMoneyService.count(query);
		PageUtils pageUtils = new PageUtils(hotelEveryDayMoneyList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("hotel:hotelEveryDayMoney:edit")
	String add(HotelEveryDayMoney hotelEveryDayMoney,HttpServletRequest request,HttpServletResponse response){
	    return "hotel/hotelEveryDayMoney/hotelEveryDayMoneyedit";
	}

	@PostMapping("/getById")
	@ResponseBody
	R getById(HotelEveryDayMoney hotelEveryDayMoney) {
		return R.ok().put("i",hotelEveryDayMoney);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("hotel:hotelEveryDayMoney:edit")
	public R save( HotelEveryDayMoney hotelEveryDayMoney){
	
		if(hotelEveryDayMoneyService.save(hotelEveryDayMoney)>0){
			return R.ok();
		}
		return R.error();
	}
	
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("hotel:hotelEveryDayMoney:edit")
	public R remove( Long id){
		if(hotelEveryDayMoneyService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("hotel:hotelEveryDayMoney:edit")
	public R remove(@RequestParam("ids[]") Long[] ids){
		hotelEveryDayMoneyService.batchRemove(ids);
		return R.ok();
	}
	
}